//
// Created by cheng on 25-3-16.
//
#include "terminal.h"
#include "define.h"
#include "utils.h"
#include "draw.h"
#include <termios.h>
#include "game.h"
#include "control.h"



/*
    https://harddrop.com/wiki/Term_Correspondence_Chart
*/



void init() {
    tc::hide_cursor();
    gm::start_listenner();
    gm::init();
}

void loop() {
    int i = 1;
    while (gm::running) {
        
        tc::clean_screen();

        dw::window(1, 1, 9, 6, "Hold");
        dw::window(1, 10, 12, 22, "Tetris");
        dw::window(7, 1, 9, 16, "Status");
        dw::window(19, 22, 8, 4, "Info");
        dw::window(1, 22, 8, 18, "Next");
        tc::move_to(10, 5);
        std::cout << "FPS: " << ut::fps() << std::endl;

        tc::move_to(gm::row, ut::block2col(gm::col));
        // tc::set_back_color(15);
        // std::cout <<"  ";
        
        dw::tetromion(gm::cur_s, gm::row, gm::col, gm::cur_index);
        tc::reset_color();
        std::cout << std::flush;
        std::this_thread::sleep_for(500ms);
    }
}

void exit() {
    tc::show_cursor();
    tc::reset_color();
    tc::clean_screen();
    tc::move_to(1, 1);
    tc::set_fron_color(9);
    std::cout << "Bye!" << std::endl;
}

int main(int argc, char* argv[]) {
    init();
    loop();
    exit();
    return 0;
}